home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / ZWnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  5.4 KB  |  244 lines

  1. // ZWnd.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Radiant.h"
  6. #include "ZWnd.h"
  7. #include "qe3.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CZWnd
  17. IMPLEMENT_DYNCREATE(CZWnd, CWnd);
  18.  
  19.  
  20. CZWnd::CZWnd()
  21. {
  22. }
  23.  
  24. CZWnd::~CZWnd()
  25. {
  26. }
  27.  
  28.  
  29. BEGIN_MESSAGE_MAP(CZWnd, CWnd)
  30.     //{{AFX_MSG_MAP(CZWnd)
  31.     ON_WM_CREATE()
  32.     ON_WM_DESTROY()
  33.     ON_WM_KEYDOWN()
  34.     ON_WM_LBUTTONDOWN()
  35.     ON_WM_MBUTTONDOWN()
  36.     ON_WM_RBUTTONDOWN()
  37.     ON_WM_PAINT()
  38.     ON_WM_GETMINMAXINFO()
  39.     ON_WM_MOUSEMOVE()
  40.     ON_WM_SIZE()
  41.     ON_WM_NCCALCSIZE()
  42.     ON_WM_KILLFOCUS()
  43.     ON_WM_SETFOCUS()
  44.     ON_WM_CLOSE()
  45.     ON_WM_LBUTTONUP()
  46.     ON_WM_MBUTTONUP()
  47.     ON_WM_RBUTTONUP()
  48.     ON_WM_KEYUP()
  49.     //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CZWnd message handlers
  55.  
  56. int CZWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  57. {
  58.     if (CWnd::OnCreate(lpCreateStruct) == -1)
  59.         return -1;
  60.  
  61.     g_qeglobals.d_hwndZ = GetSafeHwnd();
  62.  
  63.   m_dcZ = ::GetDC(GetSafeHwnd());
  64.   QEW_SetupPixelFormat(m_dcZ, false);
  65.     if ((m_hglrcZ = qwglCreateContext(m_dcZ )) == 0)
  66.       Error("wglCreateContext in CZWnd::OnCreate failed");
  67.  
  68.     if (!qwglShareLists(g_qeglobals.d_hglrcBase, m_hglrcZ))
  69.       Error( "wglShareLists in CZWnd::OnCreate failed");
  70.  
  71.   if (!qwglMakeCurrent(m_dcZ, m_hglrcZ))
  72.       Error ("wglMakeCurrent in CZWnd::OnCreate failed");
  73.  
  74.     return 0;
  75. }
  76.  
  77. void CZWnd::OnDestroy() 
  78. {
  79.   QEW_StopGL(GetSafeHwnd(), m_hglrcZ, m_dcZ);
  80.     CWnd::OnDestroy();
  81. }
  82.  
  83. void CZWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  84. {
  85.   g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
  86. }
  87.  
  88. void CZWnd::OnLButtonDown(UINT nFlags, CPoint point) 
  89. {
  90.   SetFocus();
  91.   SetCapture();
  92.   CRect rctZ;
  93.   GetClientRect(rctZ);
  94.     Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  95. }
  96.  
  97. void CZWnd::OnMButtonDown(UINT nFlags, CPoint point) 
  98. {
  99.   SetFocus();
  100.   SetCapture();
  101.   CRect rctZ;
  102.   GetClientRect(rctZ);
  103.     Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  104. }
  105.  
  106. void CZWnd::OnRButtonDown(UINT nFlags, CPoint point) 
  107. {
  108.   SetFocus();
  109.   SetCapture();
  110.   CRect rctZ;
  111.   GetClientRect(rctZ);
  112.     Z_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  113. }
  114.  
  115. void CZWnd::OnPaint() 
  116. {
  117.     CPaintDC dc(this); // device context for painting
  118.   //if (!wglMakeCurrent(m_dcZ, m_hglrcZ))
  119.   if (!qwglMakeCurrent(dc.m_hDC, m_hglrcZ))
  120.   {
  121.     Sys_Printf("ERROR: wglMakeCurrent failed..\n ");
  122.     Sys_Printf("Please restart Q3Radiant if the Z view is not working\n");
  123.   }
  124.   else
  125.   {
  126.       QE_CheckOpenGLForErrors();
  127.     Z_Draw ();
  128.       //qwglSwapBuffers(m_dcZ);
  129.       qwglSwapBuffers(dc.m_hDC);
  130.     TRACE("Z Paint\n");
  131.   }
  132. }
  133.  
  134. void CZWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
  135. {
  136.     lpMMI->ptMinTrackSize.x = ZWIN_WIDTH;
  137. }
  138.  
  139. void CZWnd::OnMouseMove(UINT nFlags, CPoint point) 
  140. {
  141.   CRect rctZ;
  142.   GetClientRect(rctZ);
  143.   float fz = z.origin[2] + ((rctZ.Height() - 1 - point.y) - (z.height/2)) / z.scale;
  144.     fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  145.   CString strStatus;
  146.   strStatus.Format("Z:: %.1f", fz);
  147.   g_pParentWnd->SetStatusText(1, strStatus);
  148.   Z_MouseMoved (point.x, rctZ.Height() - 1 - point.y, nFlags);
  149. }
  150.  
  151. void CZWnd::OnSize(UINT nType, int cx, int cy) 
  152. {
  153.     CWnd::OnSize(nType, cx, cy);
  154.   CRect rctZ;
  155.   GetClientRect(rctZ);
  156.   z.width = rctZ.right;
  157.     z.height = rctZ.bottom;
  158.   if (z.width < 10)
  159.     z.width = 10;
  160.   if (z.height < 10)
  161.     z.height = 10;
  162.   Invalidate();
  163. }
  164.  
  165. void CZWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
  166. {
  167.     CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  168. }
  169.  
  170. void CZWnd::OnKillFocus(CWnd* pNewWnd) 
  171. {
  172.     CWnd::OnKillFocus(pNewWnd);
  173.     SendMessage(WM_NCACTIVATE, FALSE , 0 );
  174. }
  175.  
  176. void CZWnd::OnSetFocus(CWnd* pOldWnd) 
  177. {
  178.     CWnd::OnSetFocus(pOldWnd);
  179.     SendMessage(WM_NCACTIVATE, TRUE , 0 );
  180. }
  181.  
  182. void CZWnd::OnClose() 
  183. {
  184.     CWnd::OnClose();
  185. }
  186.  
  187. void CZWnd::OnLButtonUp(UINT nFlags, CPoint point) 
  188. {
  189.   CRect rctZ;
  190.   GetClientRect(rctZ);
  191.     Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  192.     if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  193.       ReleaseCapture ();
  194. }
  195.  
  196. void CZWnd::OnMButtonUp(UINT nFlags, CPoint point) 
  197. {
  198.   CRect rctZ;
  199.   GetClientRect(rctZ);
  200.     Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  201.     if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  202.       ReleaseCapture ();
  203. }
  204.  
  205. void CZWnd::OnRButtonUp(UINT nFlags, CPoint point) 
  206. {
  207.   CRect rctZ;
  208.   GetClientRect(rctZ);
  209.     Z_MouseUp (point.x, rctZ.bottom - 1 - point.y, nFlags);
  210.     if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  211.       ReleaseCapture ();
  212. }
  213.  
  214.  
  215. BOOL CZWnd::PreCreateWindow(CREATESTRUCT& cs) 
  216. {
  217.   WNDCLASS wc;
  218.   HINSTANCE hInstance = AfxGetInstanceHandle();
  219.   if (::GetClassInfo(hInstance, Z_WINDOW_CLASS, &wc) == FALSE)
  220.   {
  221.     // Register a new class
  222.       memset (&wc, 0, sizeof(wc));
  223.     wc.style         = CS_NOCLOSE | CS_OWNDC;
  224.     wc.lpszClassName = Z_WINDOW_CLASS;
  225.     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
  226.     wc.lpfnWndProc = ::DefWindowProc;
  227.     if (AfxRegisterClass(&wc) == FALSE)
  228.       Error ("CZWnd RegisterClass: failed");
  229.   }
  230.  
  231.   cs.lpszClass = Z_WINDOW_CLASS;
  232.   cs.lpszName = "Z";
  233.   if (cs.style != QE3_CHILDSTYLE)
  234.     cs.style = QE3_SPLITTER_STYLE;
  235.  
  236.     return CWnd::PreCreateWindow(cs);
  237. }
  238.  
  239.  
  240. void CZWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
  241. {
  242.   g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
  243. }
  244.